(function() {
	//省市 区三级联动
	$(function() {
		var pro = $("#pro"),
			city_name = $("#city"),
			direct_id = $("#direct"),
			xuanzechengshi=$("#xuanzechengshi"),
			xuanzediqu=$("#xuanzediqu");
			/*点击空白的时候加上请选择地区和选择城市*/
			var li_city="<li>请选择城市</li>";
			city_name.append(li_city);
			var li_direct="<li>请选择地区</li>";
			direct_id.append(li_direct);
		$.each(province, function(k, p) {
			var li = "<li data-id='" + p.ProID + "'>" + p.ProName + "</li>";
			pro.append(li);
			
		});
		$("#pro li").on("click", function() {
			$("#city li").remove();
			$("#direct li").remove();
			/*清楚城市以及地区的值**/
			xuanzechengshi.val("");
			xuanzediqu.val("");
			var pro_val = $(this).data("id");
			$.each(city, function(k, p) {
				if(p.ProID == pro_val) {
					var li = "<li data-id='" + p.CityID + "'>" + p.CityName + "</li>";
					city_name.append(li);
				}
			});
		});
		$("#city").on("click", "li", function() {
			$("#direct li").remove();
			xuanzediqu.val("");
			/*点击请选择城市的时候加上请选择地区*/
			var li_direct="<li>请选择地区</li>";
			direct_id.append(li_direct);
			var city_val = $(this).data("id");
			$.each(District, function(k, p) {
				if(p.CityID == city_val) {
					var li = "<li data-id='" + p.ID + "'>" + p.DisName + "</li>";
					direct_id.append(li);
				}
			});
		})
	});
	
	/*******文本框*******/
	$(function(){
		var i=0,
		textarea=$("textarea[data-leiming]"),
		zishu=$(".baifenbai a"),
		area_val="";
			textarea.on("keyup",function(){
				var textarea_val=textarea.val();
				if(textarea[0].value==''){
					zishu.text("0");
				}else{
					var reg = /[\u4e00-\u9fa5\w]/g;
					if(textarea_val.match(reg).length>100){
						textarea_val=area_val;
					}else{
						area_val=textarea_val;
						zishu.text(area_val.length);
					}
				}
			});
	})
    $(function(){
        var i=0,
            textarea=$("textarea[data-leiming2]"),
            zishu=$(".wenbenkuangzishu"),
            area_val="";
        textarea.on("keyup",function(){
            var textarea_val=textarea.val();
            if(textarea[0].value==''){
                zishu.text("0");
            }else{
                var reg = /[\u4e00-\u9fa5\w]/g;
                if(textarea_val.match(reg).length>100){
                    textarea_val=area_val;
                }else{
                    area_val=textarea_val;
                    zishu.text(area_val.length);
                }
            }
        });
    })
	/****邮编地址****/
	var youbian_tishi=$(".youdiquhao"),
		youbian_input=$("#youbiandizhi");
	youbian_input.on("focus",function(){
		youbian_tishi.css("opacity","0");
		youbian_input.val("");
		youbian_input.css("color","#878787");
	})
	youbian_input.on("blur",function(){
		var youbian_val=$("#youbiandizhi").val();
		var r3=/^[0-9]{6}$/;
		if(r3.test(youbian_val)==false){
			youbian_tishi.css("opacity","1");
			youbian_input.val("请输入6位数字");	
			youbian_input.css("color","#eb413d");
		}
	})	
	/*客户备注部分**/
	$(".beizhu").on("focus",function () {
		$(".shanchu input[type='text']").css("display","none");
		$(".shanchu textarea").css({
            "width":"500px",
            "height":"100px",
            "lineHight":"100px",
			"display":"block",
			"float":"left",
		});
		$(".shanchu a").css("display","inline-block");
        $("textarea[data-leiming2='wenbenkuang']").prop("autofocus","autofocus");
    })
    $("textarea[data-leiming2='wenbenkuang']").on("blur",function () {
        $(".shanchu input[type='text']").val( $(".shanchu textarea").val());
        $(".shanchu textarea").css("display","none");
        $(".shanchu input[type='text']").css({
            "display":"block",
            "float":"left"
        });
        $(".shanchu a").css("display","none");
    })
	/********收货地址部分**********/
	$(".address").each(function () {
		$(this).on("click",function () {
			$(".address").removeClass("hong");
			$(this).addClass("hong");
        })
    })
	$(".address a").each(function () {
		$(this).on("click",function () {
			$(".address a").removeClass("active");
			$(this).addClass("active");
            $(".address a").text("设为默认");
			$(this).text("默认地址")
        })
    })

	/***********点击修改改变当前样式*********/
	
	$(".address > span").each(function () {
		$(this).on("click",function () {
			$(".woddz_mask12").css("display","block");
			$(".woddz_mask12 #mask_x").on("click",function () {
                $(".woddz_mask12").css("display","none");
            })
            $(".woddz_mask12 .btn_184").on("click",function () {
                $(".woddz_mask12").css("display","none");
            })

        })
    })
    $(".xinzhengdizhi").on("click",function () {
            $(".woddz_mask12").css("display","block");
            $(".woddz_mask12 #mask_x").on("click",function () {
                $(".woddz_mask12").css("display","none");
            })
            $(".woddz_mask12 .btn_184").on("click",function () {
                $(".woddz_mask12").css("display","none");
            })

        })
	
	
})();